package ru.compscicenter.uno.view.animation;

/**
 * Created by IntelliJ IDEA.
 * User: Павел
 * Date: 24.03.12
 * Time: 10:57
 * To change this template use File | Settings | File Templates.
 */
public class ActionAnimation {
    private final long startTime;
    private final long maxTime;
    private final int dt;
    private final static float START_OPACITY = 1.0f;
    private final static float FINISH_OPACITY = 0.0f;
    private final float dOpacity = FINISH_OPACITY - START_OPACITY;

    public ActionAnimation(long startTime, long maxTime) {
        this.startTime = startTime;
        this.maxTime = maxTime;
        dt = (int) (maxTime - startTime)/2;        
    }

    public boolean isFinished(int timeAfterStart) {
        return timeAfterStart >= (maxTime - startTime);
    }

    public long getStartTime() {
        return startTime;
    }
    
    public float getOpacity(int timeAfterStart){
        if (isFinished(timeAfterStart)) {
            return FINISH_OPACITY;
        }
        if(timeAfterStart > dt){
            return START_OPACITY + dOpacity * (timeAfterStart-dt) / dt;
        }   else {
            return START_OPACITY;
        }
    }
}
